package com.shop.test;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.shop.entity.Dept;
import com.shop.entity.Name;
import com.shop.entity.Person;
import com.shop.util.HibernateUtil;

public class DeptDaoTest2 {
	private Session session;
	private Transaction tx ;
	@Test
	public void testList(){
		Person p = new Person();
		p.setId(1001);
		p.setAge(30);
		p.setName("呵呵");
		p.getSchools().add("小学");
		p.getSchools().add("中学");
		p.getSchools().add("大学");
		
		p.getBooks().add("三体");
		p.getBooks().add("白鹿原");
		p.getBooks().add("人工智能");
		
		String [] movies = {"变形金刚5","冈仁波齐","木乃伊5","盗墓笔记"};
		p.setMovies(movies);
		
		Map<String,Float> scores = new HashMap<String,Float>();
		scores.put("语文", 100F);
		scores.put("数学", 96F);
		scores.put("英语", 98F);
		
		p.setScores(scores);
		
		Name names = new Name("无忌","张");
		p.setNames(names);
		session.save(p);
	}
	
	@Test
	public void testSave(){
		BigDecimal b = new BigDecimal(1234.4567);
		Dept dept = new  Dept(b,"AAA", "BBB") ;
		session.save(dept);
	}
	
	@Before
	public void before(){
		//1.获取session对象
		session  =HibernateUtil.getSesssion();
		tx =session.beginTransaction();
	}
	@After
	public void after(){
		tx.commit();
		//5.关闭资源
		HibernateUtil.closeSession(session);
	}
	
	
	
	
	@Test
	public  void testGet() {
		Session session  =HibernateUtil.getSesssion();
	    Dept dept  =session.get(Dept.class, 1);
	    System.out.println(dept);
	    HibernateUtil.closeSession(session);
	}
}
